﻿using System;
using Codeflows;
using Codeflows.Results;
using Codeflows.Tracking;

namespace CodeflowsTests
{
    public class CodeflowRunResult<T> where T : Codeflow
    {
        public ICodeflowTrackerFactory TrackerFactory { get; private set; }        
        public T Codeflow { get; private set; }
        public Guid CodeflowId { get; private set; }
        public Result Result { get; private set; }
    
        public CodeflowInstance PersistedInstance
        {
            get
            {
                return TrackerFactory.CreateTracker()
                    .Instance
                    .Read(CodeflowId);
            }
        }

        public CodeflowRunResult(ICodeflowTrackerFactory trackerFactory, T codeflow,
                                 Guid codeflowId, Result result)
        {
            if (trackerFactory == null) throw new ArgumentNullException("trackerFactory");
            if (codeflow == null) throw new ArgumentNullException("codeflow");
            if (result == null) throw new ArgumentNullException("result");

            TrackerFactory = trackerFactory;            
            Codeflow = codeflow;
            CodeflowId = codeflowId;
            Result = result;
        }
    }
}